package com.nio.file;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class TestC {
	public static void main(String[] args) {

		try {
			RandomAccessFile aFile = new RandomAccessFile("/usr/local/project/mm/wholepr/aaa/src/main/java/desc", "rw");

			FileChannel inChannel = aFile.getChannel();

			ByteBuffer buf = ByteBuffer.allocate(48);

			int bytesRead = inChannel.read(buf);

			while (bytesRead != -1) {

				System.out.println("Read " + bytesRead);

				buf.flip();

				while (buf.hasRemaining()) {

					System.out.print((char) buf.get());

				}

				buf.clear();

				bytesRead = inChannel.read(buf);

			}

			aFile.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("===================end");

	}
}
